// 2025/09/15
// Author: Forever
#include <bits/stdc++.h>
using namespace std;

int64_t n, mod, p, q, r, t, u, v, w, x, y, z;

class Matrix {
public:
    int64_t n, m;
    __int128_t a[105][105];
    Matrix(int64_t N, int64_t M)
    {
        n = N, m = M;
        memset(a, 0, sizeof(a));
    }
    Matrix(int64_t N)
    {
        n = N, m = N;
        memset(a, 0, sizeof(a));
        for (int64_t i = 1; i <= n; i++)
            a[i][i] = 1;
    }
    Matrix operator*(Matrix b)
    {
        Matrix c(n, b.m);
        for (int64_t i = 1; i <= n; i++)
            for (int64_t j = 1; j <= b.m; j++)
                for (int64_t k = 1; k <= m; k++)
                    c.a[i][j] += a[i][k] * b.a[k][j], c.a[i][j] %= mod;
        return c;
    }
    __int128_t* operator[](int64_t x)
    {
        return a[x];
    }
};

Matrix quick_pow(Matrix a, int64_t k)
{
    Matrix ans(a.n, a.n);
    for (int64_t i = 1; i <= a.n; i++)
        ans.a[i][i] = 1;
    while (k) {
        if (k & 1)
            ans = ans * a;
        a = a * a;
        k >>= 1;
    }
    return ans;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> mod;
    cin >> p >> q >> r >> t;
    cin >> u >> v >> w >> x >> y >> z;
    Matrix A(11, 11), B(11, 1);
    A[1][1] = p, A[1][2] = q, A[1][3] = 1, A[1][5] = 1, A[1][7] = r, A[1][8] = t, A[1][9] = 1;
    A[2][1] = 1;
    A[3][1] = 1, A[3][3] = u, A[3][4] = v, A[3][5] = 1, A[3][10] = 1;
    A[4][3] = 1;
    A[5][1] = 1, A[5][3] = 1, A[5][5] = x, A[5][6] = y, A[5][8] = 1, A[5][9] = 2, A[5][11] = 1;
    A[6][5] = 1;
    A[7][7] = 1, A[7][8] = 2, A[7][9] = 1;
    A[8][8] = 1, A[8][9] = 1;
    A[9][9] = 1;
    A[10][10] = w;
    A[11][11] = z;
    B[1][1] = 3, B[2][1] = 1, B[3][1] = 3, B[4][1] = 1, B[5][1] = 3, B[6][1] = 1, B[7][1] = 1, B[8][1] = 1, B[9][1] = 1, B[10][1] = w, B[11][1] = z;
    Matrix ans = quick_pow(A, n - 2) * B;
    cout << "nodgd " << (int64_t)ans[1][1] << endl;
    cout << "Ciocio " << (int64_t)ans[3][1] << endl;
    cout << "Nicole " << (int64_t)ans[5][1] << endl;
    return 0;
}